import { GetterTree, ActionTree, MutationTree } from 'vuex'

// state
export const state = () => ({
  token: "" as string,
  userInfo: {} as {[key: string]: any},
})

export type RootState = ReturnType<typeof state>

// getters
export const getters: GetterTree<RootState, RootState> = {
  userName: state => state.userInfo?.userName,
}

// mutations
export const mutations: MutationTree<RootState> = {
  SET_USER_INFO: (state, value: {[key: string]: any}) => (state.userInfo = value),
}

// actions
export const actions: ActionTree<RootState, RootState> = {
  setUserInfo({ commit }) {
    // this.$api.getUserInfo()
    commit('SET_USER_INFO', { userName: "张三", age: 18 })
  },
}
